﻿using System;
using System.Windows.Input;
using DailyPoetryX.Services;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using Xamarin.Essentials;
using Xamarin.Forms;

namespace DailyPoetryX.ViewModels {
    public class AboutViewModel : ViewModelBase {
        /******** 构造函数 ********/

        private IRootNavigationService rootNavigationService;

        public AboutViewModel(IRootNavigationService rootNavigationService) {
            this.rootNavigationService = rootNavigationService;
        }

        /******** 绑定属性 ********/

        /******** 绑定命令 ********/

        public RelayCommand<string> OpenUrlCommand => _openUrlCommand ??
            (_openUrlCommand = new RelayCommand<string>(async url =>
                await Browser.OpenAsync(url,
                    BrowserLaunchMode.SystemPreferred)));

        private RelayCommand<string> _openUrlCommand;

        public RelayCommand OkCommand => _okCommand ?? (_okCommand =
            new RelayCommand(async () =>
                await rootNavigationService.NavigateToAsync(
                    RootNavigationServiceConstants.TodayPage)));

        private RelayCommand _okCommand;
    }
}